import { service, getData } from '@vimi/utils-api'
// @ts-check

const DEVICE_TYPE_RFID = 'RFID'
// eslint-disable-next-line no-unused-vars
const DEVICE_TYPE_VIDEO = 'VIDEO'

/**
 * 获取设备列表
 * @param {string} farmId customer_id
 * @param {DEVICE_TYPE_RFID|DEVICE_TYPE_VIDEO} deviceType device type
 */
export const getDevice = ({ farmId, deviceType = DEVICE_TYPE_RFID }) =>
  service
    .get('/iot-proxy/device/listing', {
      params: {
        customerId: farmId,
        deviceType,
      },
    })
    .then(res => res.data || [])

/**
 * 获取RFID统计数据
 * @param {*} param
 */
export const getRfidCount = ({ startTime, endTime, deviceId, farmId }) =>
  getData('iot', deviceId ? 'rfid_data_count' : 'rfid_data_all_count', {
    isBIQuery: 1,
    'customer_id.eq': deviceId ? '' : farmId,
    'start_time.gte': startTime,
    'end_time.lte': endTime ? endTime + ' 23:59:59' : '',
    'device.eq': deviceId,
  }).then(res => res.data || [])
